{include file='/public/header'}
  <body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>类别
              </label>
              <div class="layui-input-inline">
                  <select name="pid">
                      <option value="0">顶级分类</option>
                      {volist name="add" id='vo'}
                      <option value="{$vo.id}">{$vo.name}</option>
                      {/volist}
                  </select>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  <span class="x-red">*</span>分类名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="" name="name" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  <span class="x-red">*</span>状态
              </label>
              <div class="layui-input-inline">
                  <input type="checkbox" name="status" title="热销" value="1">
              </div>
          </div>
      </form>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" onclick="insert()">保存</button>
        </div>
      </div>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            form = layui.form;
            layer = layui.layer;
            $ = layui.jquery;
        });
        //保存
        function insert(){
          var name = $.trim($('input[name="name"]').val());
          var pid = $.trim($('select[name="pid"]').val()); 
          if(name==''){
            layer.alert('请输入分类名称',{'icon':2,'anim':6});
            return;
          }
          $.post('{:url("type/insert")}',$('form').serialize(),function(res){
            if(res.code>0){
              layer.alert(res.msg,{icon:6});
            }else{
              layer.msg(res.msg);
              setTimeout(function(){parent.window.location.reload();},1000);
            }
          },'json');
        }
    </script>
  </body>

</html>